<template>
	<!-- 54是搜索框整体高度  52是tab的整体高度  不展示搜索框时需去除54-->
	<view class="page" :style="{'min-height':h+'px','padding-top':(mt+54+52)+'px'}">
		<!-- 头部 -->
		<u-navbar title="船票+景点订单" :leftIconSize="36" bgColor="#ffffff" leftIconColor="#333333" :titleStyle="titleStyle"
			@leftClick="returnBack"></u-navbar>
		<TopTabs :list="tabList" @changeTab="changeTab" :top="mt" :placeholder="'输入景点名称/订单号'" @sousuo="sousuo">
		</TopTabs>
		<view class="orders">
			<view v-for="(item,index) in orderList" :key="index">
				<view class="top">
					<view class="left">
						<image src="@/static/my/cp_zs.png" mode=""></image>
						<text :class="item.status==3?'qx':''">船景通票</text>
					</view>
					<view class="right">
						<text :class="oscConfig[item.status]">{{osConfig[item.status]}}</text>
					</view>
				</view>
				<view class="content" @click="orderDetail(item)">
					<view class="title">{{item.jointName}}</view>
					<view class="date">
						<text>{{item.sailDate||'2023-11-23'}}</text>
						<text>{{item.priceType==1?'成人票':'儿童票'}} * {{item.num}}</text>
					</view>
					<view class="room_price">
						<text :class="item.status==3?'qx':''">¥{{item.realityPay||290}}</text>
					</view>
				</view>
				<!-- 已退款 -->
				<view class="btns" v-if="item.status==2">
					<view @tap="deleteOrder(item)">删除</view>
					<view @tap="againReserve(item)">再次预订</view>
				</view>
				<!-- 待使用 -->
				<view class="btns" v-if="item.status==1">
					<view @tap="cancelOrder(item)">取消订单</view>
					<!-- <view @tap="proof(item)">发票/报销</view> -->
					<view @tap="againReserve(item)">再次预订</view>
				</view>
				<!-- 待支付 -->
				<view class="btns" v-if="item.status==0">
					<view @tap="cancelOrder(item)">取消</view>
					<view @tap="toPay(item)" style="color: #007A69;">去支付</view>
				</view>
				<!-- 已完成 -->
				<view class="btns" v-if="item.status==3">
					<view @tap="deleteOrder(item)">删除</view>
					<view @tap="goToAppraise(item)">评价</view>
					<view @tap="againReserve(item)">再次预订</view>
				</view>
			</view>
		</view>
		<!-- <view class="tip">{{orderList.length>0?'已显示全部订单':'暂无订单'}}</view> -->

		<view style="background: white;padding-bottom: 10vh;" v-if="orderList.length ==0">
			<nodata></nodata>
		</view>
	</view>
</template>

<script>
	import nodata from '@/compoments/NoData/index.vue'
	import TopTabs from '../../compoments/TopTabs/topTabs.vue';
	export default {
		name: 'landmarkTicketOrder',
		components: {
			TopTabs,
			nodata
		},
		data() {
			return {
				mysearch: '',
				h: uni.getSystemInfoSync().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				titleStyle: {
					fontSize: '36rpx',
					fontWeight: "bold",
					color: "#333333"
				},
				tabList: [{
						name: '全部'
					},
					{
						name: '待支付'
					},
					{
						name: '待使用'
					},
					{
						name: '退款/售后'
					}
				],
				orderList: [],
				osConfig: {
					0: '待支付',
					1: '待使用',
					2: '已退款'
				},
				oscConfig: {
					1: 'textDzf',
					2: 'textDcx',
					3: 'textQx'
				},
				fromList: {
					limit: 10,
					openId: 0,
					page: 1
				},
				openId: 0,
				orderState: ''

			}
		},
		onLoad() {
			// console.log(localStorage.setItem(userInfo), '0010010+00+00+0+0+');
			// 获取本地存储中的数据
			// console.log('99-9-9-9-9-9-9-9-9-', this.openId);
			try {
				var data = wx.getStorageSync('userInfo'); // 替换成你要获取的数据的键名
				if (data) {
					// 数据获取成功
					this.fromList.openId = JSON.parse(data).openId
					console.log(this.fromList.openId, '333');
				} else {
					// 未找到对应数据
					console.log('未找到数据');
				}
			} catch (e) {
				// 获取数据时出错
				console.log('获取数据出错', e);
			}

			this.gtiList()

		},
		methods: {
			goToAppraise(item) {
				console.log(item, 'item');
				const obj = {
					guideId: item.id,
					orderCode: item.orderCode,
					sourceType: 7
				}

				uni.navigateTo({
					url: '/pagesMy/appraise/appraise?obj=' + JSON.stringify(obj)
				})
			},
			orderDetail(item) {
				uni.navigateTo({
					// url: '/pagesTrip/packageArea/order?orderCode=' + item.id
					url: '/pagesTrip/packageArea/order?orderCode=' + item.id
				})
			},
			changeTab(index) {
				if (index === 0) this.orderState = '';
				else if (index === 1) this.orderState = '0'
				else if (index === 2) this.orderState = '1,2';
				else this.orderState = '-2,-1,3,4,5,6,7,8,9,10,11';
				this.gtiList();
			},
			//删除
			deleteOrder(item) {
				console.log(item, 'item');
			},
			//再次预订
			againReserve(item) {
				console.log(item, 'item');
			},
			//入园凭证
			proof(item) {
				console.log(item, 'item');
			},
			//取消订单
			cancelOrder(item) {
				console.log(item, 'item');
			},
			//发票/报销
			invoice(item) {
				console.log(item, 'item');
			},
			//去支付
			toPay(item) {
				this.orderId = item.orderCode
				this.lsKey = 'toPay';
				this.$login().then(res => {
					if (res === 0) return this.confrimPay();
				})
			},
			confrimPay(item) {
				this.$api.post('/order/icbc/createOrder', {
					orderCode: this.orderId,
					tradeType: 'JSAPI',
					openId: JSON.parse(uni.getStorageSync('userInfo')).openId
				}, false).then(res => {
					if (res.statusCode == 200 && res.data != null) {
						this.payShow = false;
						this.$wxPay(res.data).then(result => {
							uni.navigateTo({
								url: '/pagesTrip/scenicSpots/paySuccess?type=shipAnd&orderId=' +
									this.orderId
							})
						})
					}
				})
			},
			sousuo(keyword) {
				this.mysearch = keyword;
				// this.FormData.page=1;
				// this.FormData.limit=10;
				this.gtiList();
			},

			gtiList() {
				this.$api.get('/api/shipScenic/getSsPersonalOrderList', {
						openId: JSON.parse(uni.getStorageSync('userInfo')).openId,
						// openId: 'o3nWX4haEqIpN8YnSds-iCRNJ9Fc',
						page: 1,
						limit: 50,
						orderState: this.orderState,
						condition: this.mysearch,
					})
					.then(res => {
						this.orderList = res.data.data.list
					})
			},
			returnBack() {
				uni.reLaunch({
					url: '/pages/my/index'
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page {
		background: #F5F8FA;
		padding: 100rpx 0 1rpx;

		.orders {
			display: flex;
			flex-direction: column;
			align-items: center;

			&>view {
				width: calc(100% - 96rpx);
				margin-top: 20rpx;
				border-radius: 16rpx;
				background: #fff;
				padding: 36rpx 24rpx 24rpx;

				.top {
					display: flex;
					justify-content: space-between;

					.left {
						display: flex;
						align-items: center;

						image {
							width: 36rpx;
							height: 36rpx;
						}

						text {
							font-size: 28rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #111111;
							line-height: 28rpx;
							margin-left: 20rpx;
						}
					}

					.right {
						text-align: right;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						line-height: 37rpx;
					}
				}

				.content {
					padding: 22rpx 0 24rpx 56rpx;
					border-bottom: 1rpx solid #EFEFEF;
					background: #fff;
					position: relative;

					.title {
						font-size: 32rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #333333;
						line-height: 45rpx;
					}

					.date {
						text {
							display: block;
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #AAAAAA;
							line-height: 24rpx;
							margin-top: 20rpx;
						}
					}

					.room_price {
						position: absolute;
						bottom: 12px;
						right: 0;
						z-index: 1;

						text {
							font-size: 32rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #AAAAAA;
							line-height: 32rpx;
						}

					}
				}

				.btns {
					display: flex;
					align-items: center;
					justify-content: flex-end;

					&>view {
						margin: 24rpx 0 0 24rpx;
						width: 148rpx;
						height: 56rpx;
						border: 1rpx solid #EFEFEF;
						border-radius: 28rpx;
						line-height: 56rpx;
						text-align: center;
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
				}
			}
		}

		.tip {
			width: 100%;
			text-align: center;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #AAAAAA;
			line-height: 33rpx;
			margin: 56rpx 0;
		}

		.qx {
			color: #AAAAAA !important;
		}

		.textQx {
			color: #AAAAAA;
		}

		.textDcx {
			color: #333;
		}

		.textDzf {
			color: #FF7D01;
		}
	}
</style>